#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QLineEdit>
#include <QTextEdit>
#include <QTableView>
#include <QStandardItemModel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusInterface>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QList>
#include <QFile>

const QString serviceServerName = "com.mytest.dbus";
const QString serviceServerPath = "/com/mytest/dbus";
const QString serviceServerInterface = "com.mytest.dbus.interface";
const QString fileName = "history.json";

class MainWindow : public QMainWindow {
    Q_OBJECT
    // 声明Dbus接口,property
    Q_CLASSINFO("D-Bus Interface", "com.mytest.dbus.interface")
    Q_PROPERTY(QString demoProperty READ getProperty WRITE setProperty NOTIFY demoPropertyChanged)

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void setupUI();
public slots:
    // 服务端接收客户端发送的信息
    Q_INVOKABLE void receiveMessage(const QString &message);
    QString getProperty();
    void setProperty(const QString& newProperty);
signals:
    void demoPropertyChanged(const QString& newProperty);


private:
    QTableView* table;
    QStandardItemModel* tableModel;
    QTextEdit* output;
    void loadHistory();
    void saveHistory(const QJsonObject& json);
    void setupDBus();
    QString demoProperty;
};

#endif // MAINWINDOW_H
